package com.itheima.exception;

import com.itheima.common.CommonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//全局异常处理器
@RestControllerAdvice
public class GlobalExceptionAdvice {

    //处理自定义的异常
    @ExceptionHandler(BusinessException.class)
    public CommonResult handlerBusinessException(Exception exception) {
        //打印异常
        exception.printStackTrace();

        //返回错误
        return CommonResult.error(exception.getMessage());
    }

    //处理普通异常异常
    @ExceptionHandler(Exception.class)
    public CommonResult handlerException(Exception exception) {
        //打印异常
        exception.printStackTrace();

        //返回错误
        return CommonResult.error("网络繁忙~~~");
    }
}